package com.ror.java.se.inet.udp;

//Java使用UDP协议发送数据：
//- 创建发送端的DatagramSocket对象
//- 数据打包：创建DatagramPacket对象
//- 发送数据
//- 释放资源

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Demo01UdpSender {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket();
        byte[] msgBuf = "Hello, UDP!".getBytes();
        InetAddress ip = InetAddress.getLocalHost();
        int port = 10086;
        DatagramPacket dp = new DatagramPacket(msgBuf, msgBuf.length, ip, port);
        ds.send(dp);
        ds.close();
    }
}
